package Text_60;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Set;

public class Code {

	public static void main(String[] args) {
		//创建数组放置景点
        String[] arr = {"A","B","C","D"};
        //用于放置投票的数据
        ArrayList<String> list = new ArrayList<>();
        Random r = new Random();
        //每个人的投票结果
        for (int i = 0; i < 80; i++) {
            //随机投票
            int index = r.nextInt(arr.length);
            //放入集合
           list.add (arr[index]);
        }
        //利用Map来统计票数
        HashMap<String,Integer> hm = new HashMap<>();
        //遍历
        for(String name: list){
            //判断是否景点存在
            if(hm.containsKey(name)){
                //获取当前已经投的票数
                int count = hm.get(name);
                //自增
                count++;
                //覆盖
                hm.put(name,count);
            //不存在，表示第一次，直接添加
            }else{
                hm.put(name,1);
            }
        }
        System.out.println(hm);
        //求最大值
        int max = 0;
        //存储键值
        Set<Map.Entry<String, Integer>> entries = hm.entrySet();
        for(Map.Entry<String, Integer> entry:entries){
            int count = entry.getValue();
            if(count>max){
                max = count;
            }
        }
        System.out.println(max);
        //值找键
        for(Map.Entry<String, Integer> entry:entries){
            int count = entry.getValue();
            if(count==max){
                System.out.println(entry.getKey());
            }
        }

	}

}
